<?php

class Controller_Test_Memcache extends Controller_Test_Abstract
{
    public $autoRender = false;

    protected $_cache;

    public function init()
    {
        $this->_cache = new Com_Cache_Memcache('global');
    }

    public function indexAction()
    {
        $this->_dump($this->_cache);
        $this->_dump($this->_cache->getStats());
        $this->_dump($this->_cache->getVersion());
        $this->_dump($this->_cache->flush());

        echo '<h1>-------set/get array ---- ' . '</h1>';
        $this->_dump($this->_cache->set('array', array(
            'key1' => 'value1',
            'key2' => 'value2',
            'key3' => 'value3'
        )));
        $this->_dump($this->_cache->get('array'));
        $this->_dump($this->_cache->delete('array'));
        $this->_dump($this->_cache->get('array'));

        echo '<h1>-------set/get/add/replace string ---- ' . '</h1>';
        $this->_dump($this->_cache->set('hello', 'world'));
        $this->_dump($this->_cache->add('hello', 'world in add'));
        $this->_dump($this->_cache->replace('hello', 'world in replace'));
        $this->_dump($this->_cache->get('hello'));

        echo '<h1>-------incr/decr ---- ' . '</h1>';
        $this->_cache->increment('counter');
        $this->_cache->increment('counter', 10);
        $this->_dump($this->_cache->get('counter'));

        $this->_cache->decrement('counter');
        $this->_dump($this->_cache->get('counter'));
        $this->_cache->decrement('counter', 10);
        $this->_dump($this->_cache->get('counter'));

        echo '<h1>-------mget/mset ---- ' . '</h1>';
        $items = array(
            'key1' => 'value1',
            'key2' => 'value2',
            'key3' => 'value3'
        );
        $keys = array_keys($items);
        $this->_dump($this->_cache->setMulti($items));
        $this->_dump($this->_cache->getMulti($keys));

        $this->_dump($this->_cache->getMulti($keys, $casTokens, 1));
        $this->_dump($casTokens);
        echo '-------';
        //$this->_dump($this->_cache->getResultCode());

        $keys[] = 'non';
        $this->_dump($this->_cache->getMulti($keys));
        //$this->_dump($this->_cache->getResultCode());

        return false;
    }

    public function orgAction()
    {
        $org = new Memcache();
        $org->addServer('127.0.0.1', '11211');
        $org->addServer('192.168.2.155', '11211');
        $this->_dump($org->get('kkk'));

        return false;
    }
}
